package vn.aptech.leaveManagementSystem.business.model;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import vn.aptech.leaveManagementSystem.business.dto.Department;
import vn.aptech.leaveManagementSystem.dao.DBManager;

public class Departments extends DBManager{
	
	public int addDepartment(Department dep) throws SQLException
	{
		getConn();
		String sql="{Call sp_InsertDepartment(?)}";
		CallableStatement cs=conn.prepareCall(sql);
		cs.setString(1, dep.getDepartmentName());
		return cs.executeUpdate();
	}
	
	public int updateDepartment(Department dep) throws SQLException
	{
		getConn();
		String sql="{Call sp_UpdateDepartmentName(?,?)}";
		CallableStatement cs=conn.prepareCall(sql);
		cs.setInt(1, dep.getIDDepartment());
		cs.setString(2, dep.getDepartmentName());
		return cs.executeUpdate();
	}
	
	public int deleteDepartment(int idDep) throws SQLException
	{
		getConn();
		String sql="{Call sp_DeleteDepartment(?)}";
		CallableStatement cs=conn.prepareCall(sql);
		cs.setInt(1, idDep);
		return cs.executeUpdate();
	}
	
	public ResultSet getDepartment(int idDep) throws SQLException
	//IDDepartment, DepartmentName
	{
		getConn();
		String sql="{Call sp_getDepartment(?)}";
		CallableStatement cs=conn.prepareCall(sql);
		cs.setInt(1, idDep);
		ResultSet rs=cs.executeQuery();
		return rs;
	}
	
	public ResultSet getDepartmentList() throws SQLException
	//IDDepartment, DepartmentName
	{
		getConn();
		String sql="{Call sp_getDepartmentList}";
		CallableStatement cs=conn.prepareCall(sql);
		ResultSet rs=cs.executeQuery();
		return rs;
	}
	
	public ResultSet getManagerOfThisDepartment(int idDep) throws SQLException
	//Employee.*
	{
		getConn();
		String sql="{Call sp_getManagerOfThisDepartment(?)}";
		CallableStatement cs=conn.prepareCall(sql);
		cs.setInt(1, idDep);
		ResultSet rs=cs.executeQuery();
		return rs;
	}
	public static void main(String[] args) throws SQLException {
		Departments d=new Departments();
		ResultSet rs=d.getDepartmentList();
	}
}
